<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>$this->y_title.'列表'),
);
$credit_types=credit_types(true);
$xunibititle=$credit_types[$this->setting['jian_feetype']]?:'R币';
if($_RQ['op']=='list'){
	if($_RQ['id']){
		$this->session('cangid',$_RQ['id']);
	}
	$cangid=$this->session('cangid');
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'cangid'=>$cangid);
	if(isset($_RQ['paixu'])){
		$params['paixu']=intval($_RQ['paixu']);
		$return['params']['paixu']=intval($_RQ['paixu']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_jicai_yao',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$v){
			$this->model('model')->up_yao($v);
			$v['isfee']=pdo_getsum('jy_jicai_canlog',array('yaoid'=>$v['id'],'cangid'=>$this->session('cangid'),'uniacid'=>$_SESSION['uniacid']),'jifen');
			$v['isget']=pdo_getsum('jy_jicai_feelog',array('type'=>0,'yaoid'=>$v['id'],'cangid'=>$this->session('cangid'),'uniacid'=>$_SESSION['uniacid']),'fee');
			$v['zhiget']=pdo_getsum('jy_jicai_feelog',array('type'=>5,'yaoid'=>$v['id'],'cangid'=>$this->session('cangid'),'uniacid'=>$_SESSION['uniacid']),'fee');
			$v['jiget']=pdo_getsum('jy_jicai_feelog',array('type'=>6,'yaoid'=>$v['id'],'cangid'=>$this->session('cangid'),'uniacid'=>$_SESSION['uniacid']),'fee');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'paixu','title'=>'第几'.$this->y_title,'type'=>'unitstring','unit'=>$this->y_title),
			array('name'=>'alljifee','title'=>'满额积分','type'=>'string'),
			array('name'=>'isfee','title'=>'已投入积分','type'=>'string'),
			array('name'=>'isget','title'=>'投入积分收益','type'=>'string'),
			array('name'=>'zhiget','title'=>'直推积分收益','type'=>'string'),
			array('name'=>'jiget','title'=>'级差积分收益','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'yao_status'),
			array('name'=>'startime','title'=>'开始时间','type'=>'time'),
			array('name'=>'endtime','title'=>'结束时间','type'=>'time'),
		),'action'=>array(
			//array('type'=>'post','op'=>'up_success','title'=>'补收益','show'=>array('status'=>array(5))),
			array('type'=>'href','action'=>'/yaologxuni/','title'=>$xunibititle.'参与记录','show'=>array('status'=>array(0))),
			array('type'=>'href','op'=>'up_yue','title'=>'预约参与','show'=>array('status'=>array(0))),
		)),
		'search'=>array(
			array('name'=>'paixu','width'=>15,'title'=>'第几'.$this->y_title,'type'=>'string'),
		),
	);
	$return['types']=$this->feelog_type;
	$return['yao_status']=$this->yao_status;
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='up_yue'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'mid'=>trim($post['mid']),
			'jifen'=>trim($post['jifen']),
		);
		$id=intval($post['id']);
		if($id){
			pdo_update('jy_jicai_yuelog',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			exi('修改成功！','','list');
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['yaoid']=$post['yaoid'];
			$data['cangid']=$post['cangid'];
			$data['createtime']=TIMESTAMP;
			pdo_insert('jy_jicai_yuelog',$data);
			exi('添加成功！','','list');
		}
	}
	$yao=$this->get('yao',array('id'=>intval($_RQ['id'])));
	if(!$yao){
		exi('指定期不存在！','error');
	}
	$item=$this->get('yuelog',array('yaoid'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		$yao['yaoid']=$yao['id'];
		unset($yao['id']);
		$item=$yao;
	}else{
		$item['paixu']=$yao['paixu'];
	}
	$item['paixu']='第'.$item['paixu'].$this->y_title;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'设置预约',
		'edit'=>array(
			array('name'=>'paixu','title'=>'第几'.$this->y_title.'的预约','type'=>'copy'),
			array('type'=>'choose','name'=>'mid','title'=>'选择预约人(超级管理员)','action'=>'core/member.get_member/','help'=>'方便管理员自己参与预约，让建仓数据好看些'),
			array('name'=>'jifen','title'=>'输入预约建仓积分数量','type'=>'unitstring','unit'=>'个'),
		),
	);
	exi($return);
}
if($_RQ['op'] == 'up_success'){
	$id=intval($_RQ['id']);
	$yao=pdo_get('jy_jicai_yao',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if(!$yao['id'] && $yao['status']!=5){
		exi('不存在！或状态不对！','error');
	}
	$isget=pdo_count('jy_jicai_feelog',array('type'=>0,'yaoid'=>$yao['id'],'uniacid'=>$_SESSION['uniacid']));
	if($isget){
		exi('已经发收益了，不能再发放了！','error');
	}
	$cang=pdo_get('jy_jicai_cang',array('id'=>$yao['cangid'],'uniacid'=>$_SESSION['uniacid']));
	$jian_getrate=$cang['jian_getrate'];
	$canlogs=pdo_getall('jy_jicai_canlog',array('yaoid'=>$yao['id'],'uniacid'=>$_SESSION['uniacid']));
	foreach($canlogs as $cv){
		$this->model('model')->up_tofee($cv,$jian_getrate);
	}
	exi('补收益成功！');
}